#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>

#include <curses.h>

#include <stdlib.h>

char buf[2048];
FILE *fp,*fplogfile;
void handler()
{

}

int main( int argc, char *argv[] )
{
    int i;
    if(argc != 3 )
    {
        printf("Usage: root# ./ShowProc [proc file name] [log file name]\n");
        exit(0);
    }

    if((fplogfile=fopen(argv[2],"w+"))==NULL)
    {
        printf("Warning: File(%s) can not open.",argv[2]);
        exit(0);
    }
    signal(SIGALRM,handler);
    while(1)
    {
        alarm(1);
        pause();
        system("clear");

        if((fp=fopen(argv[1],"rb"))==NULL)
        {
            printf("Warning: File(%s) can not open.",argv[1]);
            fclose(fplogfile);
            exit(0);
        }
        while(fgets(buf,2047,fp))
        {
            i = 0;
            printf("%s",buf);
            fprintf(fplogfile,"%s",buf);
            while(buf[i])
            {
                if(buf[i] == '\n') buf[i] = ';';
                i++;
            }
        }
        fclose(fp);
    }
    return 0;
}
